<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>如何获取随机验证码</title>
    
</head>
<body>
    <script type="text/javascript">
        function random(max,min){
            return Math.floor(Math.random()*(max-min)+min);
        }
        // 随机验证码 四位 数字+字母(大写)
        function creatCode(){
            // 设置默认字符串
            var code = '';
            // 设置长度
            var codeLength = 4;
            var randomCode = [0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
            for(var i=0;i<codeLength;i++){
                // 设置随机范围 0~36
                var index = random(0,36);
                code += randomCode[index];
            }
            return code;
        }
        for(var i=1;i<100;i++){
            document.write(`<p>${creatCode()}</p>`);
        }
    </script>
</body>
</html>